/**
 * 
 */
package com.conn.service.socket.req;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

/**
 * @author lushouzhi
 *
 */
public class EndianUtils {
	
	private ByteBuffer buffer=null;
	
	public EndianUtils(byte []bytes){
		buffer=ByteBuffer.wrap(bytes);
	}
	
	public byte getByte(){
		return buffer.get();
	}

	public short getShort(){
		return buffer.getShort();
	}
	
	public int getInt(){
		return buffer.getInt();
	}
	
	public long getLong(){
		return buffer.getLong();
	}
	
	public String getString(){
		short len=buffer.getShort();
		byte []value=new byte[len];
		buffer.get(value, 0, len);
		String val = null;
		try {
			val = new String(value,"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return val;
	}
	
	
}
